<%-- 
    Document   : addAnswer
    Created on : 07/10/2011, 11:22:07 AM
    Author     : s4200768
--%>


<script language="javascript"> 
    window.onload = begin;
    var Polltype;
    
    function changeType(type){
        Polltype= type;
    }
    
    function begin(){
        addBlank(1,10);
        enable(1,10);
        disable(3,10);
    }
    
    function addText(text, textbox){
        var box = document.getElementById(textbox);
        box.value = text;
    }
            
    function addBlank(start, end){
        for (var i=start; i<=end ; i++){
            addText('', 'ANSWER'+i);
                    
        }
    }
    
    function disable(start, end){
        for (var i=start; i<=end ; i++){
            addText('', 'P'+i);
            document.getElementById('ANSWER'+i).disabled = true;
            document.getElementById('C'+i).disabled = true;
            document.getElementById('P'+i).disabled = true;
                    
        }
    }
                  
    function enable(start, end){
        for (var i=start; i<=end ; i++){
            addText('1', 'P'+i);
            document.getElementById('ANSWER'+i).disabled = false;
            document.getElementById('C'+i).disabled = false;
            document.getElementById('P'+i).disabled = false;
        }
    }
    
    function isEnabled(){
        for (var i=1; i<=10 ; i++){
            var check = document.getElementById('ANSWER'+i).disabled;
            if (check == true){
                document.getElementById('ANSWER'+i).disabled=false;
                document.getElementById('P'+i).disabled=false;
                document.getElementById('C'+i).disabled=false;
                addText('1', 'P'+i);
                break;
            }
        }
        
    }
    
            
    function checkForm(){
        var question = document.getElementById('MCQuestion').value;
        
        if (question == ""){
            alert("Please fill in a question");
            return false;
        }
        for (var i=1 ; i<=10 ; i++){
            var current = document.getElementById('ANSWER'+i).value;
            var currentPoint = document.getElementById('P'+i).value;
            if (current != "" && currentPoint != "" ){
                return true;
            }
        }
        alert("Please fill in the answer field");
        return false;

    }
    function check(){
        var SRanswer = document.getElementById('SRKeywords').value;
        if (SRanswer == ""){
            alert("Please fill in a answer");
            return false;
        }
        alert("Answer has been set successfuly.");
        return false;

    }
    

          
</script>

<style type="text/css">
    #thing{
        position:relative;
        left:70px;
        margin-top: 0px;
    }
    #i{
        margin-bottom:20px;
    }
    #buttons{

        position:relative;  
        bottom:70px;
        padding-top:155px;
        float:left;


    }

    #h{
        color:#006633;
        font-weight: bold;
    }

    #LForm{
        float:left;
        margin-top:0px;
        padding-top:5px;
        padding-left: 80px;
        padding-right: 30px;
        padding-bottom: 30px;
    }

    #hh{
        margin-top:-10px;
        margin-left: -30px;

    }

    #i1{
        padding-left: 21px;
        padding-right: 20px;
    }

    #i3{
        padding-left:36px;
        padding-right:35px;
    }

    #i4{
        padding-left:19px;
        padding-right:19px;
    }

    #butt{
        margin-top: 15px;
    }
    #ht{
        margin-top:10px;
        margin-left: 130px;
    }
    .answers{
        padding-left: 170px;
    }

</style>

<%@ include file="../header.jsp" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<link rel="stylesheet" type="text/css" href="../style.css"/>
<div id="content-container1">
    <div id="content">
        <!-- Content goes here -->
        <div id="LForm">

            <form:form method="post" commandName="addAns" onsubmit="return checkForm();"><br />
                <%Object temps = request.getParameter("qid");%>

                <% int type = Integer.parseInt(request.getParameter("type"));
                    int tt = type;

                %>
                <% if (tt == 0) {
                %>
                <h3 id="hh">New MC Answer</h3>

                <span hidden="true">
                    <form:input path='id' type='text' value='<%=temps%>'/>    
                    <form:input path='questionType' type='text' value='<%=type%>'/>    
                </span>                
                <label><b>Enter New Answers: </b></label><br />
                <form:input path="a1" id="ANSWER1" /><form:input path="p1" id="P1" /><form:checkbox path="c1" id="C1" name="C1" />Correct<br />
                <form:input path="a2" id="ANSWER2" /><form:input path="p2" id="P2" /><form:checkbox path="c2" id="C2" name="C2"/>Correct<br />
                <form:input path="a3" id="ANSWER3" /><form:input path="p3" id="P3" /><form:checkbox path="c3" id="C3" name="C3"/>Correct<br />
                <form:input path="a4" id="ANSWER4" /><form:input path="p4" id="P4" /><form:checkbox path="c4" id="C4" name="C4"/>Correct<br />
                <form:input path="a5" id="ANSWER5" /><form:input path="p5" id="P5" /><form:checkbox path="c5" id="C5" name="C5"/>Correct<br />
                <form:input path="a6" id="ANSWER6" /><form:input path="p6" id="P6" /><form:checkbox path="c6" id="C6" name="C6"/>Correct<br />
                <form:input path="a7" id="ANSWER7" /><form:input path="p7" id="P7" /><form:checkbox path="c7" id="C7" name="C7"/>Correct<br />
                <form:input path="a8" id="ANSWER8" /><form:input path="p8" id="P8" /><form:checkbox path="c8" id="C8" name="C8"/>Correct<br />
                <form:input path="a9" id="ANSWER9" /><form:input path="p9" id="P9" /><form:checkbox path="c9" id="C9" name="C9"/>Correct<br />
                <form:input path="a10" id="ANSWER10" /><form:input path="p10" id="P10" /><form:checkbox path="c10" id="C10" name="C10"/>Correct<br />

                <div id="butt">
                    <INPUT TYPE=SUBMIT value="Submit" >
                    <input type="button" onclick="addBlank(1,10),
                    enable(1,10),
                    disable(3,10)" 
                           id="Template5" value="Clear" />
                    <input type="button" onclick="isEnabled()" 
                           id="Template6" value="Add Field" /><br />
                </div>
                <input type="button" value="Back" onClick="javascript: history.go(-1)">
            </div>
            <div id="buttons">
                <table border="1" ID="thing">
                    <th id="h">Templates</th>
                    <tr><td><input id="i1" type="button" size="20" onclick="addText('True', 'ANSWER1'), 
                    addText('False', 'ANSWER2'),
                    addBlank(3, 10),
                    enable(1,10),
                    disable(3,10)" 
                                   id="Template1" value="True/False Template" /></td></tr>
                    <tr><td> <input id="i2" type="button" onclick="addText('Yes', 'ANSWER1'), 
                    addText('No', 'ANSWER2'),
                    addText('Abstain', 'ANSWER3'),
                    addBlank(4, 10),
                    enable(1,10),
                    disable(4,10)" 
                                    id="Template2" value="Yes/No/Abstain Template" /></td></tr>
                    <tr><td><input id="i3" type="button" onclick="addText('Strongly Agree', 'ANSWER1'), 
                    addText('Agree', 'ANSWER2'),
                    addText('Neutral', 'ANSWER3'), 
                    addText('Disagree', 'ANSWER4'),
                    addText('Strongly Disagree', 'ANSWER5'),
                    addBlank(6, 10)
                    enable(1,10),
                    disable(6,10)" 
                                   id="Template3" value="Agree/Disagree" /></td></tr>

                    <tr><td><input id="i4" type="button" onclick="addText('Very Strongly Agree', 'ANSWER1'), 
                    addText('Strongly Agree', 'ANSWER2'),
                    addText('Agree', 'ANSWER3'), 
                    addText('Neutral', 'ANSWER4'),
                    addText('Disagree', 'ANSWER5')
                    addText('Strongly Disagree', 'ANSWER6')
                    addText('Very Strongly Disagree', 'ANSWER7'),
                    addBlank(8, 10),
                    enable(1,10),
                    disable(8,10)"
                                   id="Template4" value="More Agree/Disagree" /></td></tr>
                </table>

            </div>



            <% } else if (tt == 1) {%>
            <h3 id="ht">New SR Answer</h3>
            <div class="answers">
                <span hidden="true">
                    <form:input path='id' type='text' value='<%=temps%>'/>    
                    <form:input path='questionType' type='text' value='<%=type%>'/>    
                </span> 

                <label><b>Enter New Answers (Space Seperated): </b></label><br /></br>

                <form:input path="SR" id="SRKeywords" /><br /><br />
                <input type="submit" onclick="return check()" value ="Submit" /></br></br>

                <input type="button" value="Back" onClick="javascript: history.go(-1)">
            </div>
            <%} else {%>

            <%  }%>


        </form:form>
    </div>
</div>
<%@ include file="../footer.jsp" %>